package com.aryankh.service.impl;

import com.aryankh.entity.KhOperLog;
import com.aryankh.dao.KhOperLogDao;
import com.aryankh.service.KhOperLogService;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 操作日志(KhOperLog)表服务实现类
 *
 * @author makejava
 * @since 2022-05-28 07:19:50
 */
@Service("khOperLogService")
public class KhOperLogServiceImpl implements KhOperLogService {
    @Resource
    private KhOperLogDao khOperLogDao;

    /**
     * 通过ID查询单条数据
     *
     * @param operId 主键
     * @return 实例对象
     */
    @Override
    public KhOperLog queryById(Integer operId) {
        return this.khOperLogDao.queryById(operId);
    }

    /**
     * 分页查询
     *
     * @param khOperLog 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<KhOperLog> queryByPage(KhOperLog khOperLog, PageRequest pageRequest) {
        long total = this.khOperLogDao.count(khOperLog);
        return new PageImpl<>(this.khOperLogDao.queryAllByLimit(khOperLog, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param khOperLog 实例对象
     */

    @Override
    @Async("kh_logger")
    public void insert(KhOperLog khOperLog) {
        System.out.println("khlogger--------------"+Thread.currentThread().getName());
        this.khOperLogDao.insert(khOperLog);
    }

    /**
     * 修改数据
     *
     * @param khOperLog 实例对象
     * @return 实例对象
     */
    @Override
    public KhOperLog update(KhOperLog khOperLog) {
        this.khOperLogDao.update(khOperLog);
        return this.queryById(khOperLog.getOperId());
    }

    /**
     * 通过主键删除数据
     *
     * @param operId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer operId) {
        return this.khOperLogDao.deleteById(operId) > 0;
    }
}
